# -*- coding: utf-8 -*-


from typing import Optional
from dataclasses import field
from marshmallow.validate import OneOf, Range
from index.protocol import Field
from marshmallow_dataclass import dataclass


@dataclass
class FetchCommentsRequest:
    book_id: int
    page: int = 1
    page_size: int = 10
    order_by: str = field(metadata=Field(validate=OneOf(['like_count', 'create_time'])), default='like_count')


@dataclass
class FetchMyCommentsRequest:
    page: int = 1
    page_size: int = 10
    order_by: str = field(metadata=Field(validate=OneOf(['like_count', 'create_time'])), default='like_count')


@dataclass
class CommentLikeRequest:
    comment_id: int
    is_like: bool = True


@dataclass
class MyLikesRequest:
    page: int = 1
    page_size: int = 10


@dataclass
class MyLikeResponse:
    # book
    pass

@dataclass
class UpdateCommentRequest:
    comment_id: int
    rate: Optional[int] = field(metadata=Field(validate=Range(max=5, min=1, error="评分必须在{min}到{max}之间")))
    content: Optional[str] = None
